<div class="profile-content-row">
	<?php if(!empty($zapposts)){
		foreach($zapposts as $zappost){
		?>
		<?php if($zappost['media_type']!=''){?>
			<div class="postdata" id="<?=$zappost['id']?>">
				<div class="row post">
					<div class="col-xs-12 col-md-4">
						<?php if($zappost['media_type']=="image"){?>
						<img src="<?php echo base_url(); ?>assets/uploads/.thumbs/media/<?=$zappost['media']?>" alt="profile-img" class="img-responsive" />
						<?}?>
					</div>
					<div class="col-xs-12 col-md-7">
						<h2 class="mid-bar-heading"><?=$zappost['firstname'].' '.$zappost['lastname'].'('.$zappost['social_user'].')'?>&nbsp;&nbsp;&nbsp;&nbsp;Date : <?=date('m/d/Y h:i A', strtotime($zappost['date_added']));?></h2>
						<p class="mid-bar-content"><?=$zappost['post_desc']?></p>
					</div>
					<div class="col-xs-12 col-md-1">
						<div class="btn-group zapaction">
							<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
								<span class="caret"></span>
							</button>
							<ul class="dropdown-menu" role="menu">
								<?php if($zappost['userid']==$userid){?>
								<li><a href="javascript:void(0)" onclick="removecomments('<?=$zappost['id']?>')">Remove</a></li>
								<?}?>
								<li><a href="javascript:void(0)" onclick="hidecomments('<?=$zappost['id']?>')">Hide</a></li>
							</ul>
						</div>
					</div>
					<div class="clearfix"></div>
					<div class="col-md-12">
						<a href="javascript:void(0)" class="commentdiv">Comment</a>
					</div>
				</div>
				<div class="row comments" style="display:none;">
					<div class="col-md-12">
						<?php foreach($zappost['comment'] as $usercomment){?>
						<div class="media">
							<a class="pull-left" href="#">
								<img src="<?php echo base_url(); ?>assets/uploads/.thumbs/images/zap/<?php echo $usercomment['photo'] == '' ? DEFAULT_IMG : $usercomment['photo'] ; ?>" alt="Profile-img" class="media-object" height="32" width="32">
							</a>
							<div class="media-body">
								<h5 class="media-heading text-primary"><?=$usercomment['firstname']?></h5>
								<p><?=$usercomment['comments']?></p>
								<p class="text-muted"><?=date('m/d/Y h:i A', strtotime($usercomment['comment_date']));?></p>
							</div>
							<span class="glyphicon glyphicon-remove commentremove"></span>
						</div>
						<?}?>
						<div class="media">
							<a class="pull-left" href="#">
								<img src="<?php echo base_url(); ?>assets/uploads/.thumbs/images/zap/<?php echo $zapmember['photo'] == '' ? DEFAULT_IMG : $zapmember['photo'] ; ?>" alt="Profile-img" class="media-object" height="32" width="32">
							</a>
							<div class="media-body">
								<input type="text" class="form-control" name="comment" onkeyup="postcomment(event,this,'<?=$zappost['id']?>');" placeholder="Write a Comment....">
							</div>
						</div>
					</div>
				</div>
				<hr>
			</div>
			<?}else{?>
			<div class="postdata" id="<?=$zappost['id']?>">
				<div class="row post">
					<div class="col-md-11">
						<h2 class="mid-bar-heading"><?=$zappost['firstname'].' '.$zappost['lastname'].'('.$zappost['social_user'].')'?>&nbsp;&nbsp;&nbsp;&nbsp;Date : <?=date('m/d/Y h:i A', strtotime($zappost['date_added']));?></h2>
						<p class="mid-bar-content"><?=$zappost['post_desc']?></p>
					</div>
					<div class="col-xs-12 col-md-1">
						<div class="btn-group zapaction">
							<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
								<span class="caret"></span>
							</button>
							<ul class="dropdown-menu" role="menu">
								<?php if($zappost['userid']==$userid){?>
								<li><a href="javascript:void(0)" onclick="removecomments('<?=$zappost['id']?>')">Remove</a></li>
								<?}?>
								<li><a href="javascript:void(0)" onclick="hidecomments('<?=$zappost['id']?>')">Hide</a></li>
							</ul>
						</div>
					</div>
					<div class="clearfix"></div>
					<div class="col-md-12">
						<a href="javascript:void(0)" class="commentdiv">Comment</a>
					</div>
				</div>
				<div class="row comments" style="display:none;">
					<div class="col-md-12">
						<?php foreach($zappost['comment'] as $usercomment){?>
						<div class="media">
							<a class="pull-left" href="#">
								<img src="<?php echo base_url(); ?>assets/uploads/.thumbs/images/zap/<?php echo $usercomment['photo'] == '' ? DEFAULT_IMG : $usercomment['photo'] ; ?>" alt="Profile-img" class="media-object" height="32" width="32">
							</a>
							<div class="media-body">
								<h5 class="media-heading text-primary"><?=$usercomment['firstname']?></h5>
								<p><?=$usercomment['comments']?></p>
								<p class="text-muted"><?=date('m/d/Y h:i A', strtotime($usercomment['comment_date']));?></p>
							</div>
							<span class="glyphicon glyphicon-remove commentremove"></span>
						</div>
						<?}?>
						<div class="media">
							<a class="pull-left" href="#">
								<img src="<?php echo base_url(); ?>assets/uploads/.thumbs/images/zap/<?php echo $zapmember['photo'] == '' ? DEFAULT_IMG : $zapmember['photo'] ; ?>" alt="Profile-img" class="media-object" height="32" width="32">
							</a>
							<div class="media-body">
								<input type="text" class="form-control" name="comment" onkeyup="postcomment(event,this,'<?=$zappost['id']?>');" placeholder="Write a Comment....">
							</div>
						</div>
					</div>
				</div>
				<hr>
			</div>
			<?}?> 
		<?}?>
	<?}?>
</div> 
<script type="text/javascript">
	function removecomments(id)
	{
		if (confirm('Delete cannot be undone! Images will remain on the server. Are you sure you want to do this?'))
		{
			$.ajax({
				url: '<?php echo base_url()?>ajax/removecomment/'+id,
				success: function(data) {
					if(data=="deleted")
					{
						$('#'+id).fadeOut( "slow" );
					}
				},
				error: function(xhr, ajaxOptions, thrownError) {
					alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
				}
			});
		}
		else
		{
			return false;
		}
	}
    $(document).ready(function() {
		$('.commentdiv').click( function() {
			$(this).parent().parent().parent().find('.comments').slideToggle();
		});
	});
	function postcomment(ev,obj,cid)
	{
		var comment=obj.value;
		var e = ev || event;
		if(e.keyCode == 13) {
			dataString={ postid: cid, comment: comment };
			$.ajax({
				url: '<?php echo base_url()?>ajax/addcomment',
				data:dataString,
				type: "POST",
				beforeSend: function(){
				},
				success: function(data) {
					obj.value="";
					$("#"+cid).find('.comments > div').prepend(data);
					$("#"+cid).find('.comments > div div:first').slideDown("slow");
				},
				error: function(xhr, ajaxOptions, thrownError) {
					alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
				}
			});
			return false; //prevents form from being submitted.
		}
	}
</script>	   